<!-- 本页样式 -->
<style scoped>
    .del-dialog-cnt {
        font-size: 16px;
        text-align: center
    }
    .footer{
        text-align: center
    }

	.container {
		height: 460px;
	}
</style>
<!-- 页面布局-->
<template>
	<div>
		<div class="table">
			<div class="container">
				<div class="search-box">
					<div class="search-item-box">
						<el-select v-model="option" placeholder="请选择" @change="optionchange" disabled>
							<el-option v-for="item in dicts.usertype" :key="item.code" :label="item.name" :value="item.code">{{item.name}}</el-option> 
						</el-select>
					</div>
				</div>
				<div class="grid-data-box">
					<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect" text-color="#606266" active-text-color="#ffd04b">
						<el-menu-item :index="v.type" v-for="v in menulist" :key="v.type">{{v.name}}</el-menu-item>
					</el-menu>
					<div>
						<component ref="bindcom" :is="bindComponent" :componentdata="componentdata"></component>
					</div>
				</div>
			</div>
		</div>
		<div class="footer">
			<el-button @click="handleCancel()">关 闭</el-button>
			<el-button type="primary" @click="handleOk()">确 定</el-button>
		</div>
	</div>
</template>

<script> 
// import bindPeople from "@/views/uim/ams/amsuser_bind_people.vue"
// import bindBuild from "@/views/uim/ams/amsuser_bind_build.vue"
// import bindCar from "@/views/uim/ams/amsuser_bind_car.vue"
// import bindCarlot from "@/views/uim/ams/amsuser_bind_carlot.vue"
export default {
	data() {
		return {
			parampters: { 
			   userid:'', 
			   usertype:'',
			}, 
			option: "",
			menulist: [{
				type: "1",
				name: "人员",
			}],
			bindComponent: "",
			activeIndex: "1",
			componentdata: {},
			//字典集
			dicts: {}
		}
	}, 
	activated() { 
		this.init();
	},
	// 初始进入页面获取表格数据(因为是页面import引用的，所以需要用mounted函数)
	mounted() {
		this.init();
	}, 
	props: {
		sourceData: {
			required: true,
		}
	},
	methods: {
		/**
		 * 初始加载字典选项
		 */
		init() {
			//参数
			this.parampters = this.$util.trimObjStr(this.parampters);
            this.parampters.loginsid = this.sourceData.loginInfo.sessionId;
			this.parampters.userid = this.sourceData.userid ;
			this.parampters.usertype = this.sourceData.usertype ;
			// 查询用户类型字典集
			this.loadSelectOptoins('usertype');
		}, 

		/**
		 * 通用定义方法：加载下拉选择 字典
		 *  @augments dictKind 字典类型
		 */
		loadSelectOptoins(dictKind, params) {
			this.$dicts
				.loadDict(this.httpRoot.BASEURL_UIM, params, dictKind)
				.then(res => { 
					this.$set(this.dicts, dictKind, res);
					this.option = this.parampters.usertype + '';
					this.loadResbindTypes();
				});
		},

		loadResbindTypes(){
			var ps = {
					loginsid: this.$util.getLoginer().sessionId,
					usertype: this.option
			};
			this.$axios.get(this.httpRoot.BASEURL_UIM + "rest/uim/ams/amsuser/finduserbindtypes", {
          		params:ps,
        	}).then(res => {
              	if (res.data.result == "true") {
				  	//console.log(res.data.resultData) ; 
					this.menulist = res.data.resultData; 
					if(this.menulist.length>0){
						this.handleSelect( this.menulist[0].type ) ; 
					} 
			  	}
			});  
		},

		//人员类型选择
		optionchange() {
			  
		},

		//资源类型选择切换
		handleSelect( key ) { 
			var ps = {
					loginsid: this.$util.getLoginer().sessionId,
					userid:this.parampters.userid,
					usertype: this.option,
					bindtype:key,
			};
			this.$axios.get(this.httpRoot.BASEURL_UIM + "rest/uim/ams/amsuser/finduserbinds", {
          		params:ps,
        	}).then(res => {
              	if (res.data.result == "true") {
				  	console.log(res.data.resultData) ;  
			  	}
			});  
		},

		/**
		 * 关闭
		 */
		handleCancel() {
			this.$emit('cancel', this.cancelData);
		},

		/**
		 * 确定
		 */
		handleOk() {
			this.$refs.bindcom.handleOk();
			this.$emit('cancel', this.cancelData);
		},






	}
}

</script>
